from itertools import compress

# 有一个数据序列，想利用一些规则从中提取出需要的值或者是缩短序列
addresses = [
    '5412 N CLARK',
    '5148 S CLARK',
    '5800 E 58TH',
    '2122 W KEPLER'
]
counts = [0,3,10,4]

# 使用列表推导
def demo_1():
    mylist = [1,4,-5,10,-7,2,3,-1]
    print([n for n in mylist if n > 0])
    print([n for n in mylist if n < 0])

def demo_2():
    more5 = [n > 5 for n in counts]
    print(more5)
    # compress函数根据序列去选择输出对应位置为True的元素,index为2的序列为True，则输出address index=2的元素
    more5_list = list(compress(addresses, more5))
    print(more5_list)

if __name__ == '__main__':
    # demo_1()
    demo_2()